
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.util.Calendar;
import javax.swing.text.html.HTMLDocument.HTMLReader.PreAction;


/**
 *
 * @author Michael Morales
 */
public class SIngresoEntregaPanelEnc extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            IngresoDatosMaestros inEntPanel = new IngresoDatosMaestros();
            Correlativos cEntPanel = new Correlativos();

            //Captura de datos del Formulario
            //String id_entrega = request.getParameter("doce_id");
            String fecha_programada = request.getParameter("doce_fecha_programada");
            String fecha_entrega = request.getParameter("doce_fecha_entrega");
            String encargado_panel = request.getParameter("doce_encargado_panel");
            String id_factura = request.getParameter("docf_id");
            String nombre_cliente = request.getParameter("cli_nombre");
            String doced_direccion = request.getParameter("doced_direccion_entrega");
            String doced_observaciones = request.getParameter("doced_observaciones");

            //System.out.print(id_entrega +"\n"+ fecha_programada +"\n"+ fecha_entrega +"\n"+
            //        encargado_panel +"\n"+ id_factura +"\n"+ nombre_cliente +"\n"+ doced_observaciones +"\n");

            cEntPanel.cEntregaPanel();
            //System.out.print("Esta es una prueba de mensajes");
            //System.out.print(cEntPanel.CEPE + "   " + request.getParameter("doce_encargado_panel") + " " + request.getParameter("docf_id") + " " + request.getParameter("doced_direccion_entrega") + " " + request.getParameter("doced_observaciones"));
            inEntPanel.GrabarDatos_EntregaPanel(cEntPanel.CEPE + 1, fecha_programada, encargado_panel, fecha_entrega, id_factura, doced_direccion, doced_observaciones);
            out.println("<html>");
            out.println("<head>");
            out.println("<meta http-equiv='Refresh' content='0;url=Ents-Generar_Confirmacion.html'>");
            out.println("</head>");
            out.println("<body>");
            out.println("</body>");
            out.println("</html>");
        } catch (Exception e) {
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);

        PrintWriter salida = response.getWriter();
        ConexionBD BD_Con = new ConexionBD();
        try {
            //Class.forName("oracle.jdbc.driver.OracleDriver");
            //String Url = "jdbc:oracle:thin:@localhost:1521:XE";

            Connection JDBC_Con = BD_Con.DBConect();
            Statement ST_comando = JDBC_Con.createStatement();
            String Con_Query = "SELECT * FROM TBT_FACTURACION_ENC";
            ResultSet RS_Consulta = ST_comando.executeQuery(Con_Query);

            ST_comando.close();
            JDBC_Con.close();
        } catch (Exception e) {
           e.printStackTrace();
        }
    }
    public static ResultSet Resultado(){
        ConexionBD BD_Con = new ConexionBD();
        ResultSet RS_Consulta = null;
        try {
            //Class.forName("oracle.jdbc.driver.OracleDriver");
            //String Url = "jdbc:oracle:thin:@localhost:1521:XE";

            Connection JDBC_Con = BD_Con.DBConect();
            Statement ST_comando = JDBC_Con.createStatement();
            String Con_Query = "SELECT * FROM TBT_FACTURACION_ENC";
            RS_Consulta = ST_comando.executeQuery(Con_Query);

            ST_comando.close();
            JDBC_Con.close();
        } catch (Exception e) {
           e.printStackTrace();
        }
    return RS_Consulta;
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
